<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SystemController extends Controller
{
    public function systemTotal(){
        $data = $this->btKey();
        $url = env('BT_URL') . '/system?action=GetSystemTotal';
        $system = $this->send_post($url,$data);
        $system = json_decode($system);
        return view('system',['system'=>$system]);
    }

    /**
     * @param $url
     * @param $post_data
     * @return false|string
     */
    function send_post($url, $post_data) {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间（单位:s）
            )
        );
        $context = stream_context_create($options);
        return file_get_contents($url, false, $context);
    }

    public function btKey(){
        $api_sk = env('BT_SK');
        $request_time = time();
        $request_token = md5($request_time.''.md5($api_sk));
        return array('request_time'=>$request_time,'request_token'=>$request_token);
    }
}
